package ptaTest4;

import java.util.Arrays;
import java.util.Scanner;

 interface IntegerStack
{
	public  Integer push(Integer item);
	public  Integer pop();
	public  Integer peek();
	public  boolean empty();
	public  int size();
}

 class ArrayIntegerStack implements IntegerStack{
	private Integer arr[];
	private int top;
	
	
	public ArrayIntegerStack(int capacity){
		arr = new Integer[capacity];
	}

	@Override
	public Integer push(Integer item) {
	if(item == null)
		return null;
	if(top == arr.length)
		return null;
	arr[top++] = item;
	return item;
	}

	@Override
	public Integer pop() {
		if(top==0)return null;
        else return arr[--top];
	}

	@Override
	public Integer peek() {
	     if(top==0)
	        	return null;
	        else 
	        	return arr[top-1];
	}

	@Override
	public boolean empty() {
		 if(top==0)
			 return true;
	     else 
	        	return false;
	}

	@Override
	public int size() {
		 return top;
	}
	
	public void print(){
		System.out.println(Arrays.toString(this.arr));
	}


	}

public class Test453 {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		ArrayIntegerStack stack = new ArrayIntegerStack(n);
		int m=sc.nextInt();
		while(m--!=0){
			System.out.println(stack.push(sc.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		stack.print();
		m=sc.nextInt();
		while(m--!=0){
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		stack.print();
	}
}

